package com.ruoyi.business.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.framework.web.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.IntegralDetail;
import com.ruoyi.business.service.IIntegralDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分明细Controller
 * 
 * @author lcz
 * @date 2025-01-19
 */
@Api(tags = "积分明细相关接口")
@RestController
@RequestMapping("/business/integralDetail")
public class IntegralDetailController extends BaseController
{
    @Autowired
    private IIntegralDetailService integralDetailService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询积分明细列表
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:integralDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(IntegralDetail integralDetail)
    {
        startPage();
        List<IntegralDetail> list = integralDetailService.selectIntegralDetailList(integralDetail);
        return getDataTable(list);
    }

    /**
     * 导出积分明细列表
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:integralDetail:export')")
    @Log(title = "积分明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntegralDetail integralDetail)
    {
        List<IntegralDetail> list = integralDetailService.selectIntegralDetailList(integralDetail);
        ExcelUtil<IntegralDetail> util = new ExcelUtil<IntegralDetail>(IntegralDetail.class);
        util.exportExcel(response, list, "积分明细数据");
    }

    /**
     * 获取积分明细详细信息
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:integralDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(integralDetailService.selectIntegralDetailById(id));
    }

    /**
     * 新增积分明细
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:integralDetail:add')")
    @Log(title = "积分明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntegralDetail integralDetail)
    {
        return toAjax(integralDetailService.insertIntegralDetail(integralDetail));
    }

    /**
     * 修改积分明细
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:integralDetail:edit')")
    @Log(title = "积分明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntegralDetail integralDetail)
    {
        return toAjax(integralDetailService.updateIntegralDetail(integralDetail));
    }

    /**
     * 删除积分明细
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:integralDetail:remove')")
    @Log(title = "积分明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(integralDetailService.deleteIntegralDetailByIds(ids));
    }

    /** 前端接口 ***************************************************************************************************/
    /** 前端接口 ***************************************************************************************************/
    /** 前端接口 ***************************************************************************************************/

    /**
     * 查询积分明细列表
     * 接口路径：/integralDetail/front/list
     */
    @GetMapping("/front/list")
    @ApiOperation("前台查询积分明细列表")
    public TableDataInfo frontList(IntegralDetail integralDetail)
    {
        Long enterpriseId = tokenService.getUserId();
        integralDetail.setEnterpriseId(enterpriseId);
        startPage();
        List<IntegralDetail> list = integralDetailService.selectIntegralDetailList(integralDetail);
        return getDataTable(list);
    }

//    /**
//     * 获取积分明细详细信息
//     * 接口路径：/integralDetail/front/info
//     */
//    @ApiOperation("前台获取积分明细详细信息")
//    @GetMapping(value = "/front/info")
//    public R<IntegralDetail> frontInfo(@RequestParam("id") Long id)
//    {
//        return R.ok(integralDetailService.selectIntegralDetailById(id));
//    }
//
    /**
     * 点击福袋扣积分接口
     * 接口路径：/integralDetail/front/add
     */
    @ApiOperation("点击福袋扣积分接口")
    @GetMapping("/front/blessingBag")
    public AjaxResult frontBlessingBag()
    {
        return integralDetailService.frontBlessingBag();
    }
//
//    /**
//     * 修改积分明细
//     * 接口路径：/integralDetail/front/edit
//     */
//    @ApiOperation("前台修改积分明细")
//    @PostMapping("/front/edit")
//    public AjaxResult frontEdit(@RequestBody IntegralDetail integralDetail)
//    {
//        return toAjax(integralDetailService.updateIntegralDetail(integralDetail));
//    }
//
//    /**
//     * 删除积分明细
//     * 接口路径：/integralDetail/front/delete
//     */
//    @ApiOperation("前台删除积分明细")
//    @GetMapping("/front/delete")
//    public AjaxResult frontRemove(@RequestParam Long[] ids)
//    {
//        return toAjax(integralDetailService.deleteIntegralDetailByIds(ids));
//    }
}
